package cz.tomasdvorak.cars.dao;

import cz.tomasdvorak.cars.dto.Vehicle;
import cz.tomasdvorak.cars.dto.VehiclesCriteria;
import cz.tomasdvorak.cars.dto.ImageItem;
import org.apache.wicket.markup.html.form.upload.FileUpload;

import java.io.IOException;
import java.util.List;

public interface VehiclesDao {
    /**
     * Creates new initialized dto (for example image url creator included)
     * @return vehicle dao prepared for user modification
     */
    Vehicle createNewDto();

    /**
     * creates new or updates vehicle, depends on provided vehicle id, if
     * id equals -1, then create, update otherwise
     * @param vehicle vehicle to create or update
     */
    void insertOrUpdate(Vehicle vehicle);

    /**
     * Gets all vehicles filtered by provided criteria
     * @param criteria criteria used to filter vehicles
     * @return list of all vehicles filtered with {@code criteria}
     */
    List<Vehicle> getAllVehicles(VehiclesCriteria criteria);

    /**
     * Gets wehicle by its id
     * @param id id of vehicle
     * @return filled vehicle
     */
    Vehicle getById(int id);

    /**
     * Attach image to vehicle
     * @param vehicle vehicle to attach image to
     * @param fileUpload attachment
     */
    void appendImage(Vehicle vehicle, FileUpload fileUpload);

    /**
     * Gets image by vehicle id.
     * @param id Vehicle id
     * @return Image attachment
     * @throws IOException
     */
    ImageItem getImage(int id) throws IOException;
}
